Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KBS: combine CoCo Token and Jwk Token verifier #524

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

Xynnn007
Copy link
Member

@Xynnn007 Xynnn007 commented Oct 9, 2024

This patch is part of #514.

ITA token and CoCo Token are both JWTs. They both need a JWK to verify the JWT. The difference is the way to gather the JWK.

This commit combined the two logic, and add two ways to get the JWK.

  1. From the configured JwkSet when launching KBS
  2. From the JWT's Header's jwk field.

The two ways will check the jwk endorsement in different ways. The first way is to configure the trusted JwkSet from the config. The second way is to configure the trusted CA in config. Then get the public key cert chain from Jwk's x5c field. The both ways are also supported in this patch.

The difference between CoCo Token and ITA Token are where Tee Public key is embedded inside the token, this could be configured in the launch toml of KBS, because it is hard to detect during runtime.

Rust does not provide a mature crate to verify cert chain, thus openssl is used in this patch. We also abondon rustls and openssl feature of KBS because openssl is by default used. Then we use openssl by default to make the code base simpler.

Close #486

cc @mythi

@LiuPeng-running
Copy link

Good good good.

@Xynnn007 Xynnn007 marked this pull request as ready for review October 10, 2024 02:00
@Xynnn007 Xynnn007 requested a review from a team as a code owner October 10, 2024 02:00
@Xynnn007
Copy link
Member Author

Xynnn007 commented Oct 10, 2024

This PR also changes some logic of previous JWK of CoCoAS, so ptal @jialez0

Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Wdyt @mythi

kbs/src/token/mod.rs Show resolved Hide resolved
@mythi
Copy link
Contributor

mythi commented Oct 14, 2024

My earlier comment in the original PR was that my preference is to not expose "ITA" as a token type to the user and that seems to be in this PR still. I was wondering whether we could just ask users to provide the list of trust anchors and try to parse the provided file:// and OpenID config paths.

The only reason for "token type" to still exist seems to be the tee-pubkey search path in the claim. Would it make sense to have the paths configurable instead of having them implicit via the token type? The search paths config could be a list to support tokens with different paths simultaneously.

@Xynnn007
Copy link
Member Author

I was wondering whether we could just ask users to provide the list of trust anchors and try to parse the provided file:// and OpenID config paths.

Yes. This PR supports the original ITA way, s.t. provode file:// to speficy jwkset, or openid url for jwksets. The modification is the configuration name in the config file, from trusted_certs_paths to trusted_jwk_sets.

Another option is trusted_certs_paths. It's for trusted root certs to verify the jwk/x5c field within the JWT header.

The only reason for "token type" to still exist seems to be the tee-pubkey search path in the claim. Would it make sense to have the paths configurable instead of having them implicit via the token type? The search paths config could be a list to support tokens with different paths simultaneously.

Nice suggestion. The pro is flexibility while the con is extra complexity to remember the paths. I personally prefer the "token type" way as the user only needs to care about token type rather than claims inside that. I think you are caring about the name ITA to be exposed to users, so what do you prefer to name it?

@mythi
Copy link
Contributor

mythi commented Oct 15, 2024

The modification is the configuration name in the config file, from trusted_certs_paths to trusted_jwk_sets.

Another option is trusted_certs_paths. It's for trusted root certs to verify the jwk/x5c field within the JWT header.

I was not very clear earlier. My comment was that can we have just one config entry. It would be easier for the user. It should be possible to handle ["file:///foo/coco.pem", "file:///foo/ita.jwks"].

The pro is flexibility while the con is extra complexity to remember the paths

True, OTOH, we can always make known paths as the default and only provide the mechanism to add supplemental paths.

@mythi
Copy link
Contributor

mythi commented Oct 15, 2024

Would it be OK to aim fixing #519 with PR too?

@Xynnn007
Copy link
Member Author

Would it be OK to aim fixing #519 with PR too?

Probably not. Currently it is hard for KBS to detect the JWT type (CoCoAS/ITA or else) runtimely. See #519 (comment)

@Xynnn007
Copy link
Member Author

True, OTOH, we can always make known paths as the default and only provide the mechanism to add supplemental paths.

Do you mean that we have two config items

  • type: specify the token type, s.t. CoCo or ITA
  • tee_publickey_path: if this parameter is given, ignore type and try to extract tee key from this path

@mythi
Copy link
Contributor

mythi commented Oct 15, 2024

Would it be OK to aim fixing #519 with PR too?

Probably not. Currently it is hard for KBS to detect the JWT type (CoCoAS/ITA or else) runtimely. See #519 (comment)

Could kid/x5* header fields be used to map to what trust anchors we have configured. ITA token has kidand we use it to search the corresponding JWK in the JwkSet.

Do you mean that we have two config items

Just one because type isn't used for anything else than just for mapping to tee-pubkey paths. So I'm thinking could we drop type completely, have some default tee-pubkey paths and allow users to configure supplemental tee_publickey_paths.

@Xynnn007
Copy link
Member Author

Could kid/x5*header fields be used to map to what trust anchors we have configured. ITA token haskid`and we use it to search the corresponding JWK in the JwkSet.

Yes it can and it is implemented in this PR. What #519 aims is to support different public key claim path.

Just one because type isn't used for anything else than just for mapping to tee-pubkey paths. So I'm thinking could we drop type completely, have some default tee-pubkey paths and allow users to configure supplemental tee_publickey_paths.

Ok. Could you provide an example for this in your mind?

@mythi
Copy link
Contributor

mythi commented Oct 16, 2024

Could kid/x5*header fields be used to map to what trust anchors we have configured. ITA token haskid`and we use it to search the corresponding JWK in the JwkSet.

Yes it can and it is implemented in this PR. What #519 aims is to support different public key claim path.

Right, sorry. I had missed that and got side tracked when you wrote that JWT detection cannot be done easily.

Just one because type isn't used for anything else than just for mapping to tee-pubkey paths. So I'm thinking could we drop type completely, have some default tee-pubkey paths and allow users to configure supplemental tee_publickey_paths.

Ok. Could you provide an example for this in your mind?

Instead of match self.token_type we could just loop all configured/known paths until claim.pointer(path) returns Ok. For starters this could be just the two we know today (i.e., TOKEN_TEE_PUBKEY_PATH_COCO and TOKEN_TEE_PUBKEY_PATH_ITA) but maybe we want to add a config entry that allows users to add more paths to search.

@Xynnn007 Xynnn007 force-pushed the refactor-token branch 3 times, most recently from 8f2d7af to 2e9d713 Compare October 16, 2024 08:57
Actually, the ITA token and CoCo Token are both JWTs. They both need a
JWK to verify the JWT. The difference is the way to gather the JWK.

This commit combined the two logic, and add two ways to get the JWK.
1. From the configured JwkSet when launching KBS
2. From the JWT's Header's jwk field.

The two ways will check the jwk endorsement in different ways. The first
way is to configure the trusted JwkSet from the config. The second way
is to configure the trusted CA in config. Then get the public key cert
chain from Jwk's x5c field. The both ways are also supported in this
patch.

Rust does not provide a mature crate to verify cert chain, thus openssl
is used in this patch. We also abondon rustls and openssl feature of KBS
because openssl is by default used. Then we use openssl by default to
make the code base simpler.

Signed-off-by: Xynnn007 <[email protected]>
Due to RFC 7515, JWK should be part of a JOSE Header rather than claim
body.

Signed-off-by: Xynnn007 <[email protected]>
@Xynnn007
Copy link
Member Author

@mythi Adds the change that you suggested. I think it is good to have some internal defined paths together with user defined extra paths.

@mythi
Copy link
Contributor

mythi commented Oct 16, 2024

@mythi Adds the change that you suggested. I think it is good to have some internal defined paths together with user defined extra paths.

thanks! I personally feel it's better this way and I guess this now meets #519 also. My remaining concern is whether we need separate user facing config entries for trusted_certs_paths and trusted_jwk_sets.

@Xynnn007
Copy link
Member Author

Xynnn007 commented Oct 16, 2024

Well as they are different things. One is jwkset and the other is root pem certs

extra_teekey_paths: vec![],
trusted_certs_paths: vec![],
trusted_jwk_sets: vec![config.certs_file.clone()],
insecure_key: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
insecure_key: true,
insecure_key: false,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me fix this. Btw, do you think we need to rename certs_file to jwkset or something else?

Copy link
Member Author

@Xynnn007 Xynnn007 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mythi Ok. Let me response here. Actually for ITA the configure item here both are ok as it will not change the behavior.

When I re-read the part of code, I have a question whether we need token_verifier object here inside ITA backend plugin code. I am afraid that we do not.

The logic here is

  • a user requests ITA for a token (and we do not need to care about the token trustiworthy as we just call the API of ITA)
  • the user request KBS for resource (this time we should check the token trustiworthy)

wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought about the same but decided to keep it for now. We may have future feature additions like the faithful verification that further checks the token and it might be useful to do it here.

@mythi
Copy link
Contributor

mythi commented Oct 16, 2024

Well as they are different things. One is jwkset and the other is root pem certs

If the take this path, we might need a third one for "OpenID Configuration endpoints" which is what the default ITA config prefers. But my point was that some generic config entry would probably keep things simple for the users.

@Xynnn007
Copy link
Member Author

If the take this path, we might need a third one for "OpenID Configuration endpoints" which is what the default ITA config prefers. But my point was that some generic config entry would probably keep things simple for the users.

Well. There are actually three items as you said

  1. JwkSet from local
  2. JwkSet to get from OpenID endpoints
  3. Root certs to verify JWKs

The 1 and 2 are in good design currently I think, by https:// or path:// prefix to distinguish
The 3 is hard to merge into 1 or 2, as it is a PEM root cert not a JWK.

Before this patch the config item trusted_certs_paths is actually used in a wrong way, at least not a good name, because it is JwkSet for ITA rather than certs.

@mythi
Copy link
Contributor

mythi commented Oct 17, 2024

Before this patch the config item trusted_certs_paths is actually used in a wrong way, at least not a good name, because it is JwkSet for ITA rather than certs.

FWIW, ITA documentation calls these certificates: "To verify the token signature, first download the Intel Trust Authority signing certificates from the portal. " and that's why I though reusing trusted_certs_paths is fine.

Would there be any better name describing both root certs and jwksets?

@Xynnn007
Copy link
Member Author

FWIW, ITA documentation calls these certificates: "To verify the token signature, first download the Intel Trust Authority signing certificates from the portal. " and that's why I though reusing trusted_certs_paths is fine.

Well, it is somehow tricky. The things download from "https://portal.trustauthority.intel.com/certs" are actually public keys with its x5cs in JWK format. This is the same as file://xxx for trusted_jwk_sets.

like

{
      "alg": "PS384",
      "e": "AQAB",
      "kid": "c68e5a7b3aec51a3ff384fe30799d465d55b16d57ef88d05f6067559d9156cd3d5302f89fe665d1fb9a6be4602be11d8",
      "kty": "RSA",
      "n": "yE07D7FRSXLsswdeK7h22kw-Xv2K2r4NFoefWElZ6FWmLvCcd27wGEczNeKrE91SWczPtR279tTasQN6_v8qsswC5rCGYlrRWvE0vuPoUXezlV4PX0tCJJJmxWtXFXW0dChWvR1j-_viOItfR8jrybV2-DyVBgGX1ad4BLJJseglPXcofhnKYcG9gp8J2zPFqs1tu6jTW-He3Xw7ZeQNq0n4ZfrRBM3GEYVVsWGlTlqVidMhbvMXSQgz1x2QjyPC2mSUrT-JyA2xTm84Mv_Lmz6FpHXsjXMyP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BTF/8FdUG3Qop55XjQzVOaBrhjhx5zwpZZBoeJ4a+Hjrh+ebm2yqvN1nsaEIoU
G3HYuWHSt97IcYHqz5qbrHwgb+oe5i0tavklwQxf/A5i
-----END CERTIFICATE-----

The two things also work differently in code. The former one will be used to look up jwk by given kid in a token, while the latter will use the certificate to check the endorsement of the jwk in a token.

@mythi
Copy link
Contributor

mythi commented Oct 17, 2024

I agree that their content is very different. My only comment has been that for the user they are still both "token verification collateral" which is why I also asked:

Would there be any better name describing both root certs and jwksets?

If other reviewers think making them separate config entries is the right thing to do, I can live with that.

cclaudio added a commit to cclaudio/trustee that referenced this pull request Oct 19, 2024
…ugins

This is just a hack to be able to test the nebula_ca plugin.

$ cd kbs && make cli ATTESTER=snp-attester && make install-cli
$ docker compose up

$ kbs-client config --auth-private-key kbs/config/private.key set-resource-policy --policy-file  kbs/sample_policies/allow_all.rego
$ kbs-client get-resource --plugin-name "nebula_ca" --resource-path "credential?ip[ip]=10.9.8.2&ip[netbits]=21&name=podA"

Currently, the last command is failing reporting
Error: request unauthorized

and in the trustee log:
ERROR kbs::error] TokenVerifierError(TokenVerificationFailed { source: Cannot verify token since trusted JWK Set is empty })

I did not get to the bottom of the problem yet, but I think I may need
the PR confidential-containers#524 as well
@Xynnn007
Copy link
Member Author

Xynnn007 commented Oct 21, 2024

To make it clear. The current token verifier config looks like

...
[attestation_token_config]
# Path of root certificate used to verify the trustworthy of `x5c` extension in the JWT
# Defaults to empty
trusted_certs_paths = ["/path/to/trusted_cacert.pem"]

# URL (`path://` or `https://`) of the trusted JWK that can be indexed by `kid` in
# JWT Header.
# Defaults to empty
trusted_jwk_sets = ["/url/to/trusted_jwk_set"]

# Each JWT contains a TEE Public Key. Users can use the `extra_teekey_paths` field to additionally specify the path of this Key in the JWT.
# Example of `extra_teekey_paths` is `/attester_runtime_data/tee-pubkey` which refers to the key
# `attester_runtime_data.tee-pubkey` inside the JWT body claims. By default CoCo AS Token and Intel TA
# Token TEE Public Key paths are supported.
# Defaults to empty
extra_teekey_paths = [""]

# For Attestation Services like CoCo-AS, the public key to verify the JWT will be given
# in the token's `jwk` field (with or without the public key cert chain `x5c`).
#
# - If this flag is set to `true`, KBS will ignore to verify the trustworthy of the `jwk`.
# - If this flag is set to `false`, KBS will look up its `trusted_certs_paths` and the `x5c`
# field to verify the trustworthy of the `jwk`.
# Defaults to `false`
insecure_key = false

Due to latest change, KBS will not maintain both rustls and openssl
suites for HTTPS. Thus we need to delete all the options of HTTPS_CRYPTO
config in documents and codes.

Also, the latest change changes the config format of
`attestation_token_config`, this patch also applies the change.

Signed-off-by: Xynnn007 <[email protected]>
@fitzthum
Copy link
Member

fitzthum commented Oct 22, 2024

If other reviewers think making them separate config entries is the right thing to do, I can live with that.

I see no real benefit in having fewer config entries, especially if doing so could cause confusion. If we are dealing with different types of stuff we might as well make different optional config entries and add some logic to make sure one of them is set.

We can also tweak this down the road if we realize that it isn't ideal.

@mythi
Copy link
Contributor

mythi commented Oct 23, 2024

I see no real benefit in having fewer config entries, especially if doing so could cause confusion.

I was mainly thinking user experience but ok. For some users it can be confusing that data downloaded from https://portal.trustauthority.intel.com/certs don't belong to trusted_certs_paths.

Copy link
Member

@jialez0 jialez0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Xynnn007 Xynnn007 merged commit 418f5e0 into confidential-containers:main Oct 23, 2024
16 checks passed
@Xynnn007 Xynnn007 deleted the refactor-token branch October 23, 2024 06:01
@mythi
Copy link
Contributor

mythi commented Oct 23, 2024

This PR was not ready for merging. For example, you still have insecure_key: true in place.

@Xynnn007
Copy link
Member Author

Xynnn007 commented Oct 23, 2024

This PR was not ready for merging. For example, you still have insecure_key: true in place.

The configuration keeps the behavior same as before. Before this commit, the insecure key option is always true logically although there is not such a config item.

I think we can fix this in future PR.

@mythi
Copy link
Contributor

mythi commented Oct 23, 2024

Before this commit, the insecure key option is always true logically although there is not such a config item.

This was not the case for attestation_token_type = "Jwk" since it unconditionally expected to have JwkSet non-empty.

@Xynnn007
Copy link
Member Author

This was not the case for attestation_token_type = "Jwk" since it unconditionally expected to have JwkSet non-empty.

Well. For old JWK (what ITA uses), the insecure_key is not relevant to that, because ITA has a kid field in JWT. The kid is used to look up previously configured jwkset. The insecure_key only works on tokens like CoCo's, where the JWK itself is included inside the JWT.

The docs upon insecure_key is

# For Attestation Services like CoCo-AS, the public key to verify the JWT will be given
# in the token's `jwk` field (with or without the public key cert chain `x5c`).
#
# - If this flag is set to `true`, KBS will ignore to verify the trustworthy of the `jwk`.
# - If this flag is set to `false`, KBS will look up its `trusted_certs_paths` and the `x5c`
# field to verify the trustworthy of the `jwk`.

This is partially why two config items seem better to me during our previous conversion.

@mythi
Copy link
Contributor

mythi commented Oct 23, 2024

Fair enough, the functionality seems fine. My original comment was related to unresolved conversations that were not addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: We did it
Development

Successfully merging this pull request may close these issues.

Add "insecure" opt-in for Trustee AS/KBS token signing/verification
5 participants